Page({
  data: {
    userinfo: {},
    collectionNum:0
  },
  onLoad: function (options) {

  },
  onShow() {
    const userinfo = wx.getStorageSync('userInfo');
    this.setData({
      userinfo
    })
    this.collection()
  },
  //获取收藏的店铺
  collection() {
    const collection = wx.getStorageSync('collection')
    for (let i = 0; i < collection.length; i++) {
      for (let j = i + 1; j < collection.length; j++) {
        if (collection[i].goods_id === collection[j].goods_id) {
          collection.splice(j, 1);
          j = j - 1;
        }
      }
    }
    const collectionNum = collection.length
    this.setData({collectionNum})
    // 删除旧缓存 因为旧缓存里面有重复的对象数据
    wx.clearStorageSync('collection');
    // 将去重过的数据重新保存到缓存中
    wx.setStorageSync('collection', collection);
  }
})